package com.cxf.windex.rest.minaf;

import com.cxf.windex.base.msg.ObjectRestResponse;
import com.cxf.windex.base.msg.TableResultResponse;
import com.cxf.windex.base.rest.BaseRestController;
import com.cxf.windex.biz.BOrdersTaskBiz;
import com.cxf.windex.entity.BOrdersTask;
import com.cxf.windex.entity.BResouces;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: business_needs
 * @description: 订单任务接口
 * @author: chenxf
 * @create: 2018-11-07 17:08
 **/
@Api(tags = {"村广通[小程序-福] - 订单任务接口"})
@Controller
@RequestMapping("userf/ordersTask")
public class FOrdersTaskController extends BaseRestController<BOrdersTaskBiz,BOrdersTask> {
  @ApiOperation(value = "查询订单任务", notes = "查询订单任务")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "limit", value = "记录数 默认10", required = false, paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "offset", value = "页码 默认 1", required = false, paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "orderStr", value = "排序 默认desc", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "resourcesName", value = "资源名称", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "status", value = "状态  -1未开始 0待处理 1已经完成 2未完成 3审核中", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "reviewStatus", value = "审核状态   0待审核 1审核通过 2审核未通过", required = false, paramType = "query", dataType = "String"),
     @ApiImplicitParam(name = "resourcesId", value = "资源ID", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "type", value = "0海报 1语音", required = false, paramType = "query", dataType = "String"),
  })
  @RequestMapping(value = "/list", method = RequestMethod.GET)
  @ResponseBody
  public TableResultResponse<BOrdersTask> list(
      @RequestParam(defaultValue = "10") int limit, @RequestParam(defaultValue = "1") int offset,
      @RequestParam(defaultValue = "desc") String orderStr,  String resourcesName,String resourcesId,String status,String reviewStatus,String type) {
    List<BOrdersTask> items = baseBiz.list(limit, offset, orderStr,resourcesName, resourcesId,status,reviewStatus,type);
    PageInfo<BOrdersTask> pageInfo = new PageInfo<>(items);
    return new TableResultResponse<BOrdersTask>(Integer.parseInt(String.valueOf(pageInfo.getTotal())),
        offset, limit,
        items);
  }

  @ApiOperation(value = "根据ID获取订单任务信息", notes = "根据ID获取订单任务信息")
  @ApiImplicitParams({
          @ApiImplicitParam(name = "id", value = "任务ID", required = true, paramType = "query", dataType = "long")
  })
  @RequestMapping(value = "/getInfo", method = RequestMethod.GET)
  @ResponseBody
  public ObjectRestResponse getInfo(Long id){
    BOrdersTask entity=baseBiz.selectById(id);
    if(entity==null){
      return new ObjectRestResponse("找不到相关信息").rel(false);
    }
    return new ObjectRestResponse("查询成功").rel(true).result(entity);
  }

  @ApiOperation(value = "保存任务凭证信息", notes = "保存任务凭证信息")
  @RequestMapping(value = "/save", method = RequestMethod.POST)
  @ResponseBody
  public ObjectRestResponse save(BOrdersTask entity){
    baseBiz.save(entity);
    return new ObjectRestResponse("保存成功").rel(true);
  }
}
